﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Sunboxsoft.WinForm.Shell.Components
{
    public partial class MaskLayer : UserControl
    {
        private string _message;

        public MaskLayer()
        {
            SetStyle(System.Windows.Forms.ControlStyles.Opaque, true);
            //base.CreateControl();

            InitializeComponent();
        }

        public void SetText(string text)
        {
            _message = text;
            progressPanel1.Caption = text;
            Invalidate();
        }

        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);

            int left = (this.Width - progressPanel1.Width) / 2;
            int top = (this.Height - progressPanel1.Height) / 2;

            progressPanel1.Location = new Point(left, top);

            Invalidate();
        }

        //protected override CreateParams CreateParams
        //{
        //    get
        //    {
        //        CreateParams createParams = base.CreateParams;
        //        createParams.ExStyle |= 0x00000020; //0x20;  // 开启 WS_EX_TRANSPARENT,使控件支持透明
        //        createParams.ExStyle |= 0x00080000;
        //        return createParams;
        //    }
        //}
        /// <summary>
        /// 自定义绘制窗体
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            float vlblControlWidth;
            float vlblControlHeight;

            ////Pen labelBorderPen;
            //SolidBrush labelBackColorBrush;

            Color drawColor = Color.FromArgb(20, Color.Black);

            //labelBorderPen = new Pen(drawColor, 0);
            SolidBrush labelBackColorBrush = new SolidBrush(drawColor);

            base.OnPaint(e);
            vlblControlWidth = this.ClientSize.Width;
            vlblControlHeight = this.ClientSize.Height;
            //e.Graphics.DrawRectangle(labelBorderPen, 0, 0, vlblControlWidth, vlblControlHeight);
            e.Graphics.FillRectangle(labelBackColorBrush, 0, 0, vlblControlWidth, vlblControlHeight);

            //SizeF textSize = e.Graphics.MeasureString(_message, this.Font);
            //SizeF textBorderSize = new SizeF(textSize.Width + 30, textSize.Height + 20);
            //PointF textBorderPos = new PointF((this.ClientSize.Width - textBorderSize.Width) / 2, (this.ClientSize.Height - textBorderSize.Height) / 2);

            //e.Graphics.FillRectangle(Brushes.White, textBorderPos.X, textBorderPos.Y, textBorderSize.Width, textBorderSize.Height);
            //e.Graphics.DrawRectangle(Pens.Black, textBorderPos.X, textBorderPos.Y, textBorderSize.Width, textBorderSize.Height);

            //e.Graphics.DrawString(_message, this.Font, Brushes.Black, new PointF((this.ClientSize.Width - textSize.Width) / 2, (this.ClientSize.Height - textSize.Height) / 2));
        }
    }
}
